﻿#include<iostream>
#include<list>
#include<functional>
using namespace std;



int main()
{
	int array[] = { 1, 2, 3, 4, 0, 5, 6, 7, 8, 9 };

	int n = sizeof(array) / sizeof(int);

	list<int> mylist(array, array + n);

	auto it = mylist.begin();

	while (it != mylist.end())

	{

		if (*it != 0)

			cout << *it << " ";

		else

			it = mylist.erase(it);

		++it;

	}

	return 0;
}


/*

//拼接


void main()
{
	int ar1[] = { 1,2,3,4,5 };
	int n1 = sizeof(ar1) / sizeof(ar1[0]);
	list<int> lt1(ar1, ar1 + n1);

	int ar2[] = { 10,20,30,40,50 };
	int n2 = sizeof(ar2) / sizeof(ar2[0]);
	list<int> lt2(ar2, ar2 + n2);

	for (const auto& e : lt1)
		cout << e << "——>";
	cout << "Over." << endl;


	for (const auto& e : lt2)
		cout << e << "——>";
	cout << "Over." << endl;

	list<int>::iterator pos = find(lt1.begin(), lt1.end(), 3);
	//lt1.splice(pos, lt2);

	//list<int>::iterator start = find(lt2.begin(), lt2.end(), 30);
	//lt1.splice(pos, lt2, start);

	list<int>::iterator start = find(lt2.begin(), lt2.end(), 30);
	lt1.splice(pos, lt2, start,lt2.end());


	for (const auto& e : lt1)
		cout << e << "——>";
	cout << "Over." << endl;


	for (const auto& e : lt2)
		cout << e << "——>";
	cout << "Over." << endl;
}












/*

//合并



void main()
{
	int ar1[] = { 1,2,3,4,5 };
	int n1 = sizeof(ar1) / sizeof(ar1[0]);
	list<int> lt1(ar1, ar1 + n1);

	int ar2[] = { 10,20,30,40,50 };
	int n2 = sizeof(ar2) / sizeof(ar2[0]);
	list<int> lt2(ar2, ar2 + n2);

	for (const auto& e : lt1)
		cout << e << "——>";
	cout << "Over." << endl;


	for (const auto& e : lt2)
		cout << e << "——>";
	cout << "Over." << endl;

	lt1.merge(lt2);//相当于是一个剪切操作

	for (const auto& e : lt1)
		cout << e << "——>";
	cout << "Over." << endl;


	for (const auto& e : lt2)
		cout << e << "——>";
	cout << "Over." << endl;
}





/*
void main()
{
	int ar1[] = { 1,2,3,4,5 };
	int n1 = sizeof(ar1) / sizeof(ar1[0]);
	list<int> lt1(ar1, ar1 + n1);

	int ar2[] = { 10,20,30,40,50};
	int n2 = sizeof(ar2) / sizeof(ar2[0]);
	list<int> lt2(ar2, ar2 + n2);

	for (const auto& e : lt1)
		cout << e << "——>";
	cout << "Over." << endl;


	for (const auto& e : lt2)
		cout << e << "——>";
	cout << "Over." << endl;


	lt1.swap(lt2);

	for (const auto& e : lt1)
		cout << e << "——>";
	cout << "Over." << endl;


	for (const auto& e : lt2)
		cout << e << "——>";
	cout << "Over." << endl;
}












/*
void main()
{
	int ar[] = { 9,2, 3,1, 4, 7 ,5, 6,10 };
	int n = sizeof(ar) / sizeof(ar[0]);
	list<int> lt4(ar, ar + n);
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;


	lt4.remove(5);
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;

}











/*
//resize重新调整大小
void main()
{
	int ar[] = { 9,2, 3,1, 4, 7 ,5, 6,10 };
	int n = sizeof(ar) / sizeof(ar[0]);
	list<int> lt4(ar, ar + n);
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;

	cout << "size = " << lt4.size() << endl;

	lt4.resize(17);
	cout << "size = " << lt4.size() << endl;

	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;
}






/*
//反转

void main()
{
	int ar[] = { 9,2, 3,1, 4, 7 ,5, 6,10 };
	int n = sizeof(ar) / sizeof(ar[0]);
	list<int> lt4(ar, ar + n);
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;

	lt4.reverse();
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;

}













/*
void main()
{
	int ar[] = { 1,1,2,2,3,3,4,4,5,6,7,8};
	int n = sizeof(ar) / sizeof(ar[0]);
	list<int> lt4(ar, ar + n);
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;


	lt4.unique();//删除连续的重复值
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;
}




















/*

//排序

void main()
{
	int ar[] = {   9,2, 3,1, 4, 7 ,5, 6,10 };
	int n = sizeof(ar) / sizeof(ar[0]);
	list<int> lt4(ar, ar + n);
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;

	lt4.sort(greater<int>());
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;
}









/*

void main()
{
	int ar[] = { 1, 2, 3, 4, 5, 6, 7, 9,10 };
	int n = sizeof(ar) / sizeof(ar[0]);
	list<int> lt4(ar, ar + n);
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;

	lt4.clear();

	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;


	cout << lt4.max_size() << endl;//表示我们还可以存放多少个结点
}











/*
//删除
//iterator erase(iterator position);
//iterator erase(iterator first, iterator last);

void main() 
{
	int ar[] = { 1, 2, 3, 4, 5, 6, 7, 9,10 };
	int n = sizeof(ar) / sizeof(ar[0]);
	list<int> lt4(ar, ar + n);
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;

	lt4.erase(lt4.begin());
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;


	lt4.erase(--lt4.end());//因为end指向的是最后一个元素的后一个元素位置，这里是是头指针，所以我们要--
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;


	list<int>::iterator start = find(lt4.begin(), lt4.end(), 3);
	list<int>::iterator end   = find(lt4.begin(), lt4.end(), 8);

	lt4.erase( start, end);
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;


}











/*
//(1）iterator insert(iterator position, const value_type& val);
//（2）void insert(iterator position, size_type n, const value_type& val);
//（3）void insert(iterator position, InputIterator first, InputIterator last);



void main()
{
	list<int>lt1;

	lt1.insert(lt1.end(), 5);
	for (const auto& e : lt1)
		cout << e << "——>";
	cout << "Over." << endl;

	lt1.insert(lt1.end(), 3, 7);
	for (const auto& e : lt1)
		cout << e << "——>";
	cout << "Over." << endl;

	int ar[] = { 3, 4, 7, 6 };
	int n = sizeof(ar) / sizeof(ar[0]);
	list<int> lt4(ar, ar + n);

	//list<int>::iterator start = lt4.begin();
	//list<int>::iterator end = lt4.begin();
	//end++;
	//end++;

	list<int>::iterator start = find(lt4.begin(), lt4.end(), 4);
	list<int>::iterator end = find(lt4.begin(), lt4.end(), 6);


	lt1.insert(lt1.end(), start,end);

	for (const auto& e : lt1)
		cout << e << "——>";
	cout << "Over." << endl;
}


/*
void main()
{
	list<int>lt1;
	list<int>lt2(10, 7);
	for (const auto& e : lt2)
		cout << e << "——>";
	cout << "Over." << endl;

	list<int> lt3 = lt2;
	for (const auto& e : lt3)
		cout << e << "——>";
	cout << "Over." << endl;

	int ar[] = { 1, 2, 3, 4, 7, 6, 78, 98 };
	int n = sizeof(ar) / sizeof(ar[0]);
	list<int> lt4(ar, ar + n);
	for (const auto& e : lt4)
		cout << e << "——>";
	cout << "Over." << endl;


	list<int> lt5(lt4.begin(), lt4.end());
	for (const auto& e : lt5)
		cout << e << "——>";
	cout << "Over." << endl;


}
*/